#	!/usr/local/bin/perl
	use warnings;
	use strict;
	use Getopt::Std;
	my $uniPaaSSourcePath;
	my $inDataObject = 0;
	my $lookForInfoVal = 0;
	my $tableNumber = 0;
	my %opt=();
	my $opt_u ='';
	my $opt_h;
	my $opt_v;
	my $linecounter = 0;
	my $linesChangedCursor = 0;
	my $linesChangedHint = 0;
	$| = 1;  #flush STDOUT.  otherwise no output for a long time.

	sub errorUsage
	{
		print STDOUT "insufficient parameters supplied\n";
		basicUsage ();
	}
	sub basicUsage
	{
		print STDERR << "EOF";
    This program does the following:
	  1. Modifies DataSources.xml 
	  2. TBD

    usage: $0 [-vhu:]
     -u	       : UniPaaS Source path
     -h        : this (help) message
     -v        : verbose output

    example 1: $0 -u: PathToUniPaaSSourceFolder
    example 2: $0 -u: e:\\Develop\\Sarel\\UW_24Feb\\Source

EOF
		exit;
	}
	sub	modifyDataSourcesMain {
		do {
#			exit;
			$_ = <IN>;
			$linecounter++;
			# The space after DataObject is very important to distinguish from DataObjects
			if( /<\/DataObject / || /<Columns/ || /<Indexes/ ) {
				$inDataObject = 0;
				$lookForInfoVal = 0;
			}
			if( /<DataObject/ ) {
				if( /PhysicalName="([^"]+)"/ ){
					$inDataObject = 1;
					print STDOUT "\n$tableNumber Physical Name=$1";
				}
				else {
					print STDOUT "\n$tableNumber Physical Name=blank";
				}
				$tableNumber++;
			}
			if( $inDataObject && /PhysicalName="##([a-zA-Z_]+)%/ && /data_source="SQL_Hiscox("|_Config")/ ){
				$lookForInfoVal = 1;
				print STDOUT "\tTemporary Physical Name w/Data Source equal to SQL_Hiscox or SQL_Hiscox_Config $1";
			}
			if( $lookForInfoVal ){
				if ( /^(.+)<HasHint/ ){
					$linesChangedHint++;
					print "$1<HasHint val=\"N\"/>\n" #changing from val="Y" for Yes
				}
				elsif ( /^(.+)<Cursor / ){
					$linesChangedCursor++;
					print "$1<Cursor val=\"N\"/>\n"  #changing from val="D" for Default
				}
			}
			else {
				print $_;
			}
		} until eof;
		print STDOUT "\n$linesChangedHint Hint lines changed in DataSources.xml ";
		print STDOUT "\n$linesChangedCursor Cursor lines changed in DataSources.xml ";
		print STDOUT "\n$linecounter lines read from DataSources.xml ";
		print STDOUT "\nNote: the size of the output file will be larger than the input file by the number of lines because";
		print STDOUT "\n we are writing CRLFs (DOS mode) when the original may have only used LF (Unix mode) as line terminator. ";
	}
	sub modifyDataSources {
		open IN, "< $uniPaaSSourcePath\\DataSources.xml";
		open OUT, "> $uniPaaSSourcePath\\DataSources1.xml";
		select OUT;
		modifyDataSourcesMain();
		close OUT;
		close IN;
	}
# I can't get getopt to work.
#	getopt('vhu');# or errorUsage();
#	if( !defined($opt_h)) {
#		print STDOUT "h is not defined\n";
#	}
#	else {
#		print STDOUT "h = $opt_h\n";
#	}
#	if( !defined($opt_v)) {
#		print STDOUT "v is not defined\n";
#	}
#	else {
#		print STDOUT "v = $opt_v\n";
#	}
#	$uniPaaSSourcePath = $opt_u;
	getopts("vhf:",\%opt);# or errorUsage();
	$uniPaaSSourcePath = $opt{f};

	print STDOUT "uniPaaS Source Path= $uniPaaSSourcePath\n";
	modifyDataSources();
#	exit here
